package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.n.shop.annotation.RequiresLogin;
import org.n.shop.domain.entity.Address;
import org.n.shop.result.RestResult;
import org.n.shop.service.AddressService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/address")
@AllArgsConstructor
public class AddressController {
    private AddressService addressService;

    @RequiresLogin
    @RequestMapping("/all")
    public RestResult all(@RequestHeader("authorization") String authorization) {
        return addressService.all(authorization);
    }

    @RequiresLogin
    @RequestMapping("/set/default")
    public RestResult setDefault(@RequestHeader("authorization") String authorization,
                                 @RequestParam("id") int id) {
        return addressService.setDefault(authorization, id);
    }

    @RequiresLogin
    @RequestMapping("/add")
    public RestResult add(@RequestHeader("authorization") String authorization,
                          @RequestBody Address address) {
        return addressService.add(authorization, address);
    }

    @RequiresLogin
    @RequestMapping("/update")
    public RestResult update(@RequestBody Address address) {
        return addressService.update(address);
    }

    @RequiresLogin
    @RequestMapping("/del")
    public RestResult del(@RequestParam("id") int id) {
        return addressService.del(id);
    }
}
